{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本地RAG演示Demo\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.aliyun.com/pypi/simple\n",
      "Requirement already satisfied: llama-index in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (0.11.23)\n",
      "Requirement already satisfied: llama-index-agent-openai<0.4.0,>=0.3.4 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.3.4)\n",
      "Requirement already satisfied: llama-index-cli<0.4.0,>=0.3.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.3.1)\n",
      "Requirement already satisfied: llama-index-core<0.12.0,>=0.11.23 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.11.23)\n",
      "Requirement already satisfied: llama-index-embeddings-openai<0.3.0,>=0.2.4 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.2.5)\n",
      "Requirement already satisfied: llama-index-indices-managed-llama-cloud>=0.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.5.0)\n",
      "Requirement already satisfied: llama-index-legacy<0.10.0,>=0.9.48 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.9.48.post4)\n",
      "Requirement already satisfied: llama-index-llms-openai<0.3.0,>=0.2.10 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.2.16)\n",
      "Requirement already satisfied: llama-index-multi-modal-llms-openai<0.3.0,>=0.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.2.3)\n",
      "Requirement already satisfied: llama-index-program-openai<0.3.0,>=0.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.2.0)\n",
      "Requirement already satisfied: llama-index-question-gen-openai<0.3.0,>=0.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.2.0)\n",
      "Requirement already satisfied: llama-index-readers-file<0.4.0,>=0.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.3.0)\n",
      "Requirement already satisfied: llama-index-readers-llama-parse>=0.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (0.3.0)\n",
      "Requirement already satisfied: nltk>3.8.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index) (3.9.1)\n",
      "Requirement already satisfied: openai>=1.14.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-agent-openai<0.4.0,>=0.3.4->llama-index) (1.54.4)\n",
      "Requirement already satisfied: PyYAML>=6.0.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (6.0.2)\n",
      "Requirement already satisfied: SQLAlchemy>=1.4.49 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.12.0,>=0.11.23->llama-index) (2.0.36)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (3.11.2)\n",
      "Requirement already satisfied: dataclasses-json in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (0.6.7)\n",
      "Requirement already satisfied: deprecated>=1.2.9.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.2.15)\n",
      "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.0.8)\n",
      "Requirement already satisfied: filetype<2.0.0,>=1.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.2.0)\n",
      "Requirement already satisfied: fsspec>=2023.5.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (2024.10.0)\n",
      "Requirement already satisfied: httpx in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (0.27.2)\n",
      "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.6.0)\n",
      "Requirement already satisfied: networkx>=3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (3.2.1)\n",
      "Requirement already satisfied: numpy<2.0.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.26.4)\n",
      "Requirement already satisfied: pillow>=9.0.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (11.0.0)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.7.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (2.9.2)\n",
      "Requirement already satisfied: requests>=2.31.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (2.32.3)\n",
      "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (8.5.0)\n",
      "Requirement already satisfied: tiktoken>=0.3.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (0.8.0)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (4.67.0)\n",
      "Requirement already satisfied: typing-extensions>=4.5.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (4.12.2)\n",
      "Requirement already satisfied: typing-inspect>=0.8.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (0.9.0)\n",
      "Requirement already satisfied: wrapt in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.23->llama-index) (1.16.0)\n",
      "Requirement already satisfied: llama-cloud>=0.1.5 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-indices-managed-llama-cloud>=0.3.0->llama-index) (0.1.5)\n",
      "Requirement already satisfied: pandas in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-legacy<0.10.0,>=0.9.48->llama-index) (2.2.3)\n",
      "Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-readers-file<0.4.0,>=0.3.0->llama-index) (4.12.3)\n",
      "Requirement already satisfied: pypdf<6.0.0,>=5.1.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-readers-file<0.4.0,>=0.3.0->llama-index) (5.1.0)\n",
      "Requirement already satisfied: striprtf<0.0.27,>=0.0.26 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-readers-file<0.4.0,>=0.3.0->llama-index) (0.0.26)\n",
      "Requirement already satisfied: llama-parse>=0.5.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-readers-llama-parse>=0.3.0->llama-index) (0.5.14)\n",
      "Requirement already satisfied: click in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index) (8.1.7)\n",
      "Requirement already satisfied: joblib in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index) (1.4.2)\n",
      "Requirement already satisfied: regex>=2021.8.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index) (2024.11.6)\n",
      "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (2.4.3)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.3.1)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (24.2.0)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.5.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (6.1.0)\n",
      "Requirement already satisfied: propcache>=0.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (0.2.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.17.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.17.1)\n",
      "Requirement already satisfied: async-timeout<6.0,>=4.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.12.0,>=0.11.23->llama-index) (5.0.1)\n",
      "Requirement already satisfied: soupsieve>1.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from beautifulsoup4<5.0.0,>=4.12.3->llama-index-readers-file<0.4.0,>=0.3.0->llama-index) (2.6)\n",
      "Requirement already satisfied: anyio in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (4.6.2.post1)\n",
      "Requirement already satisfied: certifi in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (2024.8.30)\n",
      "Requirement already satisfied: httpcore==1.* in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.0.7)\n",
      "Requirement already satisfied: idna in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (3.10)\n",
      "Requirement already satisfied: sniffio in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.3.1)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpcore==1.*->httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (0.14.0)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from openai>=1.14.0->llama-index-agent-openai<0.4.0,>=0.3.4->llama-index) (1.9.0)\n",
      "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from openai>=1.14.0->llama-index-agent-openai<0.4.0,>=0.3.4->llama-index) (0.7.1)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.7.0->llama-index-core<0.12.0,>=0.11.23->llama-index) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.7.0->llama-index-core<0.12.0,>=0.11.23->llama-index) (2.23.4)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests>=2.31.0->llama-index-core<0.12.0,>=0.11.23->llama-index) (3.4.0)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests>=2.31.0->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.26.20)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.12.0,>=0.11.23->llama-index) (3.1.1)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.0.0)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from dataclasses-json->llama-index-core<0.12.0,>=0.11.23->llama-index) (3.23.1)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pandas->llama-index-legacy<0.10.0,>=0.9.48->llama-index) (2.9.0)\n",
      "Requirement already satisfied: pytz>=2020.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pandas->llama-index-legacy<0.10.0,>=0.9.48->llama-index) (2024.2)\n",
      "Requirement already satisfied: tzdata>=2022.7 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pandas->llama-index-legacy<0.10.0,>=0.9.48->llama-index) (2024.2)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from anyio->httpx->llama-index-core<0.12.0,>=0.11.23->llama-index) (1.2.2)\n",
      "Requirement already satisfied: packaging>=17.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.12.0,>=0.11.23->llama-index) (24.2)\n",
      "Requirement already satisfied: six>=1.5 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from python-dateutil>=2.8.2->pandas->llama-index-legacy<0.10.0,>=0.9.48->llama-index) (1.16.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install llama-index\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好！有什么可以帮助你的吗？\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 引入国内的大语言模型\n",
    "import os\n",
    "from llama_index.llms.dashscope import DashScope, DashScopeGenerationModels\n",
    "\n",
    "api_key=os.getenv(\"DASHSCOPE_API_KEY\")\n",
    "\n",
    "dashscope_llm = DashScope(model_name=\"qwen-max\",api_key=api_key)\n",
    "\n",
    "resp = dashscope_llm.complete(\"你好啊？\")\n",
    "print(resp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# https://docs.llamaindex.ai/en/stable/examples/embeddings/dashscope_embeddings/\n",
    "# 安装embedding的包，这里用在线的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.aliyun.com/pypi/simple\n",
      "Requirement already satisfied: llama-index-embeddings-dashscope in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (0.2.1)\n",
      "Requirement already satisfied: dashscope>1.10.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-embeddings-dashscope) (1.20.12)\n",
      "Requirement already satisfied: llama-index-core<0.12.0,>=0.11.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-embeddings-dashscope) (0.11.23)\n",
      "Requirement already satisfied: aiohttp in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from dashscope>1.10.0->llama-index-embeddings-dashscope) (3.11.2)\n",
      "Requirement already satisfied: requests in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from dashscope>1.10.0->llama-index-embeddings-dashscope) (2.32.3)\n",
      "Requirement already satisfied: websocket-client in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from dashscope>1.10.0->llama-index-embeddings-dashscope) (1.8.0)\n",
      "Requirement already satisfied: PyYAML>=6.0.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (6.0.2)\n",
      "Requirement already satisfied: SQLAlchemy>=1.4.49 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (2.0.36)\n",
      "Requirement already satisfied: dataclasses-json in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.6.7)\n",
      "Requirement already satisfied: deprecated>=1.2.9.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.2.15)\n",
      "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.0.8)\n",
      "Requirement already satisfied: filetype<2.0.0,>=1.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.2.0)\n",
      "Requirement already satisfied: fsspec>=2023.5.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (2024.10.0)\n",
      "Requirement already satisfied: httpx in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.27.2)\n",
      "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.6.0)\n",
      "Requirement already satisfied: networkx>=3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (3.2.1)\n",
      "Requirement already satisfied: nltk>3.8.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (3.9.1)\n",
      "Requirement already satisfied: numpy<2.0.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.26.4)\n",
      "Requirement already satisfied: pillow>=9.0.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (11.0.0)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.7.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (2.9.2)\n",
      "Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (8.5.0)\n",
      "Requirement already satisfied: tiktoken>=0.3.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.8.0)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (4.67.0)\n",
      "Requirement already satisfied: typing-extensions>=4.5.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (4.12.2)\n",
      "Requirement already satisfied: typing-inspect>=0.8.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.9.0)\n",
      "Requirement already satisfied: wrapt in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.16.0)\n",
      "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (2.4.3)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (1.3.1)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (24.2.0)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (1.5.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (6.1.0)\n",
      "Requirement already satisfied: propcache>=0.2.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (0.2.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.17.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (1.17.1)\n",
      "Requirement already satisfied: async-timeout<6.0,>=4.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from aiohttp->dashscope>1.10.0->llama-index-embeddings-dashscope) (5.0.1)\n",
      "Requirement already satisfied: click in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (8.1.7)\n",
      "Requirement already satisfied: joblib in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.4.2)\n",
      "Requirement already satisfied: regex>=2021.8.3 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from nltk>3.8.1->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (2024.11.6)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.7.0->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from pydantic<3.0.0,>=2.7.0->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (2.23.4)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests->dashscope>1.10.0->llama-index-embeddings-dashscope) (3.4.0)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests->dashscope>1.10.0->llama-index-embeddings-dashscope) (3.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests->dashscope>1.10.0->llama-index-embeddings-dashscope) (1.26.20)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from requests->dashscope>1.10.0->llama-index-embeddings-dashscope) (2024.8.30)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (3.1.1)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.0.0)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from dataclasses-json->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (3.23.1)\n",
      "Requirement already satisfied: anyio in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (4.6.2.post1)\n",
      "Requirement already satisfied: httpcore==1.* in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.0.7)\n",
      "Requirement already satisfied: sniffio in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpx->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.3.1)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from httpcore==1.*->httpx->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (0.14.0)\n",
      "Requirement already satisfied: packaging>=17.0 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (24.2)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/xiaoyumin/anaconda3/envs/rag_demo/lib/python3.9/site-packages (from anyio->httpx->llama-index-core<0.12.0,>=0.11.0->llama-index-embeddings-dashscope) (1.2.2)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install llama-index-embeddings-dashscope\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dimension of embeddings: 1536\n",
      "Input: 风急天高猿啸哀, embedding is: [-0.0016414397236336783, 0.008832508989076459, 0.02900478105058192, -0.017785269972558318, 0.03636420310819226]\n",
      "Dimension of embeddings: 1536\n",
      "Input: 渚清沙白鸟飞回, embedding is: [0.018386254425877064, 0.030720417203999994, 0.0030729495341471624, 0.01428293628869976, 0.009610721536633568]\n",
      "Dimension of embeddings: 1536\n",
      "Input: 无边落木萧萧下, embedding is: [-0.012560580693622144, 0.01129123100447832, -0.007104370773270938, 0.008313908173397515, 0.03421262931786603]\n",
      "Dimension of embeddings: 1536\n",
      "Input: 不尽长江滚滚来, embedding is: [0.003423886867908772, 0.026750783632908014, -0.001032353767748251, -0.009711388207159426, 0.0036640036092945817]\n"
     ]
    }
   ],
   "source": [
    "# imports -test\n",
    "# 在线Embedding模型的测试\n",
    "from llama_index.embeddings.dashscope import (\n",
    "    DashScopeEmbedding,\n",
    "    DashScopeTextEmbeddingModels,\n",
    "    DashScopeTextEmbeddingType,\n",
    ")\n",
    "\n",
    "# Create embeddings\n",
    "# text_type=`document` to build index\n",
    "embedder = DashScopeEmbedding(\n",
    "    model_name=DashScopeTextEmbeddingModels.TEXT_EMBEDDING_V2,\n",
    "    text_type=DashScopeTextEmbeddingType.TEXT_TYPE_DOCUMENT,\n",
    ")\n",
    "text_to_embedding = [\"风急天高猿啸哀\", \"渚清沙白鸟飞回\", \"无边落木萧萧下\", \"不尽长江滚滚来\"]\n",
    "# Call text Embedding\n",
    "result_embeddings = embedder.get_text_embedding_batch(text_to_embedding)\n",
    "# requests and embedding result index is correspond to.\n",
    "for index, embedding in enumerate(result_embeddings):\n",
    "    if embedding is None:  # if the correspondence request is embedding failed.\n",
    "        print(\"The %s embedding failed.\" % text_to_embedding[index])\n",
    "    else:\n",
    "        print(\"Dimension of embeddings: %s\" % len(embedding))\n",
    "        print(\n",
    "            \"Input: %s, embedding is: %s\"\n",
    "            % (text_to_embedding[index], embedding[:5])\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import\n",
    "from llama_index.core import Settings\n",
    "\n",
    "# llm\n",
    "Settings.llm = dashscope_llm\n",
    "# chunk\n",
    "Settings.chunk_size = 1024\n",
    "# embedding\n",
    "Settings.embed_model=embedder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core import VectorStoreIndex, SimpleDirectoryReader\n",
    "\n",
    "# 知识文件夹\n",
    "reader = SimpleDirectoryReader(\"./data/paul_graham/\")\n",
    "documents = reader.load_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Document(id_='6b0acc4a-7eac-4768-a259-b54baf33f30b', embedding=None, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/kg1.txt', 'file_name': 'kg1.txt', 'file_type': 'text/plain', 'file_size': 63, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={}, text='鲍恩撑是多少年出生的？\\n\\n1989年出生在浙江宁波', mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'),\n",
       " Document(id_='153410a4-bbf1-494d-9562-58ed39cf1004', embedding=None, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/paul_graham_essay.txt', 'file_name': 'paul_graham_essay.txt', 'file_type': 'text/plain', 'file_size': 1333, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={}, text='\\n\\n程序员的悲哀是什么？\\n996 身体吃不消，朝九晚五又感觉没追求，\\n羡慕大厂的年薪百万，又想着体制内的安逸轻松，\\n开源的技术觉得没有含金量，自己写又感觉在造轮子，\\n厌恶公司里那些技术很烂但是会溜须拍马的人精，\\n给你机会洽谈商务又抖抖嗖嗖半天整不出完整话，\\n羡慕领导吹吹牛逼写写ppt就能拿着高薪，\\n让你写ppt又词穷不会表现和吹牛，\\n \\n抱怨年轻人抢你饭碗薪资倒挂，\\n自己却又身体吃不消加不了班熬不了夜，\\n总觉得同事写的代码是一坨屎，\\n给你新需求又是想方设法应付了事，\\n既不想着技术创新也不愿意性能优化，\\n只要程序能跑起来，怎么省事怎么办，\\n想着转行又觉得其他行业薪资低，\\n一直做程序员又焦虑年龄危机和被裁员，\\n给你转岗机会心里放不下学了多年的技术，\\n不给你转岗又感觉编程不能干一辈子不能养老，\\n \\n小厂感觉没前途大厂又进不去，\\n薪资太低不愿意干高薪资连面试机会都没有，\\n总想着通过提升技术来提高薪资，\\n但是一有闲暇时间就是刷各种八卦小姐姐无心学习，\\n感觉给老板打工没有意思，\\n自己创业又惦记着每月固定工资，\\n终其一生，各种纠结和各种遗憾。', mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "documents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TextNode(id_='861de800-a155-4832-a92e-427fcd13b58d', embedding=None, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/kg1.txt', 'file_name': 'kg1.txt', 'file_type': 'text/plain', 'file_size': 63, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='6b0acc4a-7eac-4768-a259-b54baf33f30b', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/kg1.txt', 'file_name': 'kg1.txt', 'file_type': 'text/plain', 'file_size': 63, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, hash='6a470a288e5a05b57ff344886739ca52eea4d8a2972e51b26aa37f3ecd2e76ee')}, text='鲍恩撑是多少年出生的？\\n\\n1989年出生在浙江宁波', mimetype='text/plain', start_char_idx=0, end_char_idx=25, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n'), TextNode(id_='d92ec40b-5ebf-4bf9-abc7-aff9ab86e730', embedding=None, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/paul_graham_essay.txt', 'file_name': 'paul_graham_essay.txt', 'file_type': 'text/plain', 'file_size': 1333, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={<NodeRelationship.SOURCE: '1'>: RelatedNodeInfo(node_id='153410a4-bbf1-494d-9562-58ed39cf1004', node_type=<ObjectType.DOCUMENT: '4'>, metadata={'file_path': '/Users/xiaoyumin/code/ipynb/RAG/data/paul_graham/paul_graham_essay.txt', 'file_name': 'paul_graham_essay.txt', 'file_type': 'text/plain', 'file_size': 1333, 'creation_date': '2024-11-17', 'last_modified_date': '2024-11-17'}, hash='760a9c0b2dd83f81a0f89450ff44537a30c6c75cb775788f3a6da636bc929676')}, text='程序员的悲哀是什么？\\n996 身体吃不消，朝九晚五又感觉没追求，\\n羡慕大厂的年薪百万，又想着体制内的安逸轻松，\\n开源的技术觉得没有含金量，自己写又感觉在造轮子，\\n厌恶公司里那些技术很烂但是会溜须拍马的人精，\\n给你机会洽谈商务又抖抖嗖嗖半天整不出完整话，\\n羡慕领导吹吹牛逼写写ppt就能拿着高薪，\\n让你写ppt又词穷不会表现和吹牛，\\n \\n抱怨年轻人抢你饭碗薪资倒挂，\\n自己却又身体吃不消加不了班熬不了夜，\\n总觉得同事写的代码是一坨屎，\\n给你新需求又是想方设法应付了事，\\n既不想着技术创新也不愿意性能优化，\\n只要程序能跑起来，怎么省事怎么办，\\n想着转行又觉得其他行业薪资低，\\n一直做程序员又焦虑年龄危机和被裁员，\\n给你转岗机会心里放不下学了多年的技术，\\n不给你转岗又感觉编程不能干一辈子不能养老，\\n \\n小厂感觉没前途大厂又进不去，\\n薪资太低不愿意干高薪资连面试机会都没有，\\n总想着通过提升技术来提高薪资，\\n但是一有闲暇时间就是刷各种八卦小姐姐无心学习，\\n感觉给老板打工没有意思，\\n自己创业又惦记着每月固定工资，\\n终其一生，各种纠结和各种遗憾。', mimetype='text/plain', start_char_idx=2, end_char_idx=471, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n')]\n"
     ]
    }
   ],
   "source": [
    "# 文档切割\n",
    "from llama_index.core.node_parser import SentenceSplitter\n",
    "\n",
    "nodes = SentenceSplitter().get_nodes_from_documents(documents)\n",
    "\n",
    "print(nodes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 索引\n",
    "from llama_index.core.storage.docstore import SimpleDocumentStore\n",
    "\n",
    "docstore = SimpleDocumentStore()\n",
    "docstore.add_documents(nodes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core import StorageContext,SummaryIndex,SimpleKeywordTableIndex\n",
    "\n",
    "storage_context = StorageContext.from_defaults(docstore=docstore)\n",
    "summary_index = SummaryIndex(nodes, storage_context=storage_context)\n",
    "vector_index = VectorStoreIndex(nodes, storage_context=storage_context)\n",
    "keyword_table_index = SimpleKeywordTableIndex(\n",
    "    nodes, storage_context=storage_context\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(storage_context.docstore.docs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "鲍恩撑的出生地是浙江宁波。\n"
     ]
    }
   ],
   "source": [
    "query_engine = summary_index.as_query_engine()\n",
    "response = query_engine.query(\"鲍恩撑出生地是哪里？\")\n",
    "\n",
    "print(response)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "rag_demo",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
